package Offer;

public class T18_deleteNode {
    public ListNode deleteNode(ListNode head, int val) {
        ListNode pre = head, p = head.next;
        if (head.val == val) {
            return p;
        }

        while (p != null) {
            if (p.val == val) {
                pre.next = p.next;
                break;
            }else {
                pre = p;
                p = p.next;
            }

        }

        return head;
    }
}
